package com.ruoyi.welder.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.welder.domain.WelderBasicInfo;
import com.ruoyi.welder.service.IWelderBasicInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 焊工基本信息管理Controller
 * 
 * @author ruoyi
 * @date 2023-01-04
 */
@Controller
@RequestMapping("/welder/info")
public class WelderBasicInfoController extends BaseController
{
    private String prefix = "welder/info";

    @Autowired
    private IWelderBasicInfoService welderBasicInfoService;

    @RequiresPermissions("welder:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询焊工基本信息管理列表
     */
    @RequiresPermissions("welder:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WelderBasicInfo welderBasicInfo)
    {
        startPage();
        List<WelderBasicInfo> list = welderBasicInfoService.selectWelderBasicInfoList(welderBasicInfo);
        return getDataTable(list);
    }

    /**
     * 导出焊工基本信息管理列表
     */
    @RequiresPermissions("welder:info:export")
    @Log(title = "焊工基本信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WelderBasicInfo welderBasicInfo)
    {
        List<WelderBasicInfo> list = welderBasicInfoService.selectWelderBasicInfoList(welderBasicInfo);
        ExcelUtil<WelderBasicInfo> util = new ExcelUtil<WelderBasicInfo>(WelderBasicInfo.class);
        return util.exportExcel(list, "焊工基本信息管理数据");
    }

    /**
     * 新增焊工基本信息管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存焊工基本信息管理
     */
    @RequiresPermissions("welder:info:add")
    @Log(title = "焊工基本信息管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WelderBasicInfo welderBasicInfo)
    {
        return toAjax(welderBasicInfoService.insertWelderBasicInfo(welderBasicInfo));
    }

    /**
     * 修改焊工基本信息管理
     */
    @RequiresPermissions("welder:info:edit")
    @GetMapping("/edit/{welderName}")
    public String edit(@PathVariable("welderName") String welderName, ModelMap mmap)
    {
        WelderBasicInfo welderBasicInfo = welderBasicInfoService.selectWelderBasicInfoByWelderName(welderName);
        mmap.put("welderBasicInfo", welderBasicInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存焊工基本信息管理
     */
    @RequiresPermissions("welder:info:edit")
    @Log(title = "焊工基本信息管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WelderBasicInfo welderBasicInfo)
    {
        return toAjax(welderBasicInfoService.updateWelderBasicInfo(welderBasicInfo));
    }

    /**
     * 删除焊工基本信息管理
     */
    @RequiresPermissions("welder:info:remove")
    @Log(title = "焊工基本信息管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(welderBasicInfoService.deleteWelderBasicInfoByWelderNames(ids));
    }
}
